#include <iostream>
#include "TcpServer.hpp"
#include "servercalc.hpp"

ServerCalc calculator; 

void DefaultOnMessage(std::shared_ptr<Connection> connection)
{
    std::cout << "上层得到的数据：" << connection->_inbuffer << std::endl;
    //这里就可以链接之前写过的用户层协议定制的内容了。
    //处理
    std::string response_str = calculator.Handler(connection->_inbuffer);
    if(response_str.empty()) return;
    std::cout << "构建的response报文" << response_str.c_str() << std::endl;
    //发送数据  
    connection->AppendOutBuffer(response_str);
    connection->_tcp_server_ptr->Sender(connection);
}

int main()
{
    std::unique_ptr<TcpServer> svr(new TcpServer(DefaultOnMessage, 8082));
    svr->Init();
    svr->Start();
    return 0;
}
